﻿using System;
using System.Collections;
using System.Windows.Forms;
using Moonlite.ExtensionApi.ControlInterfaces;
using Moonlite.ExtensionApi.GlobalInterfaces;

namespace Moonlite.UI.Shell.Controls
{
    internal class ProjectManagerNodeSorter : IComparer
    {
        public int Compare(object x, object y)
        {
            TreeNode tx = x as TreeNode;
            TreeNode ty = y as TreeNode;
            if (tx is NativeNode && !(ty is NativeNode))
            {
                return -1;
            }
            else if (ty is NativeNode && !(tx is NativeNode))
            {
                return 1;
            }

            if (tx is AbstractCustomFolderNode && !(ty is AbstractCustomFolderNode))
            {
                return -1;
            }
            else if (ty is AbstractCustomFolderNode && !(tx is AbstractCustomFolderNode))
            {
                return 1;
            }

            if (tx is AbstractCustomNode && !(ty is AbstractCustomNode))
            {
                return -1;
            }
            else if (ty is AbstractCustomNode && !(tx is AbstractCustomNode))
            {
                return 1;
            }

            if (tx.Tag is IProjectFolder && !(ty.Tag is IProjectFolder))
            {
                return -1;
            }
            else if (ty.Tag is IProjectFolder && !(tx.Tag is IProjectFolder))
            {
                return 1;
            }

            return string.Compare(tx.Text, ty.Text);
        }
    }
}
